<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<script>
	$(function(){
		var cateName=true;//设置全局变量   提交验证时候用  初始值设置false  防止开始就提交
		$("input[type=submit]").click(function(){
			var result=true;
			if(cateName==false){
				$("#cateName").blur();
				result = false;
			}
			var session = '${admin_session}';
			if(session!=""){
				if(result==true){
						if(confirm("确认提交吗")){
							$.ajax({
								url:"CateServlet.do",
								type:"post",
								data:{id:"${cateInfo.id}",cateName:$("#cateName").val(),flag:"updateCateSmallNow",note:$(".txtarea").val(),parentId:$("#one :checked").val()},
								success:function(data){
									$("#result_msg").html(data).removeClass().addClass("validate_ok");
								}
							});
					}
				}else{
					$("#result_msg").html("请正确填写信息后保存").removeClass().addClass("validate_error");
				}
			}else{
				window.location.href="login.jsp";
			}
		});
		
		$("#cateName").blur(function(){
			var id = $(this)[0].id;
			var name=$(this).val();
			var reg=/^\S{2,20}$/g;
			if(reg.test(name)){
				$.ajax({
					url:"CateServlet.do",
					type:"post",
					data:{id:'${cateInfo.id}',cateName:$(this).val(),flag:"cateFlag"},
					success:function(data){
						
						if(data!=""){
							$("#"  +id+"_msg").html(data).removeClass().addClass("validate_error");
							cateName=false;
						}else{
							$("#"  +id+"_msg").html("√").removeClass().addClass("validate_ok");
							cateName=true;
						}
					}
				});
			}else{
				$("#"+id +"_msg").html("格式错误").removeClass().addClass("validate_error");
				cateName=false;
			}
		});
		
	});
	</script>
  </head>
  
  <body>
  				
	 	<table class="edit_table" >
	 	<tr>
	 		<td class="td_info">一级分类:</td>	
 			<td class="td_input_short">
 				 <select id="one">
	 				<c:forEach var="cate" items="${cateList }">
	 					<c:choose>
	 						<c:when test="${cate.id==cateInfo.parentId }">
	 							<option value="${ cate.id}" selected="selected">${cate.cateName }</option>
	 						</c:when>
	 						<c:otherwise>
	 							<option value="${ cate.id}">${cate.cateName }</option>
	 						</c:otherwise>
	 					</c:choose>
	 				</c:forEach>
 				</select>
 			</td>
	 	</tr>
 		<tr>
		 	<td class="td_info">分类名称:</td>	
		 	<td class="td_input_short"> 
		 		<input type="text" class="txtbox" id="cateName" name="${cateInfo.id }" value="${cateInfo.cateName }"/> 
		 	</td>   
		 	<td>
		 		<label class="validate_info" id="cateName_msg" >长度2~20位为空白字符</label>
		 	</td> 
 		</tr>
 		<tr>
			<td class="td_info">分类描述:</td>	
			<td>
				<textarea rows="4" cols="27" class="txtarea" name="note">${cateInfo.des }</textarea>
			</td> 
			<td></td>	
 		</tr>
 		<tr>
 			<td class="td_info"> </td>	
 			<td> 
 			<input class="form_btn" type="submit" value="保存修改" /> 
 			<td>
 				<label id="result_msg" class="result_msg"></label>
 			</td>	
 		</tr>
	</table>
  </body>
</html>